/**
 * Created by Administrator on 2017/12/19.申请关系转接
 */
import cookie from "js-cookie";
import { Toast } from 'antd-mobile';
import { routerRedux } from 'dva/router';
import { addTransfer,area } from '../../services/organization';

export default {
  namespace: 'applytransfers',
  state: {
    Lists:[],
    area:[],
    orgtype:[],
  },
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(({pathname, query}) => {
        if(pathname === '/work/zzgx/applytransfer') {
          dispatch({
            type:'select',
          })
        }
      })
    }
  },

  effects: {
    * fetch({payload}, {call, put, select}) {
      if (payload) {
        const data = yield call(addTransfer, payload);
        console.log("data",data);
        if(data.data.code==200){
          Toast.success('创建成功！', 1);
          //跳转到列表页
          yield put(
            routerRedux.push({
              pathname:"/work/zzgx/applyhistory",
              query:{}
            })
          );
        }
        else{
          Toast.fail(data.data.msg, 1);
        }
        yield put({
          type: 'success',
          payload: {
            Lists:data.data.ret
          }
        });
      }
    },
    * select({payload}, {call, put, select}) {
      const data = yield call(area, payload);
      if (data.data.code == 200) {
        yield put({
          type: 'success',
          payload: {
            area: data.data.ret
          }
        });
      }
      else {
        Toast.success('查询失败！', 1);
      }
    }
  },
  reducers: {
    success(state, action){
      return {...state, ...action.payload};
    }
  }
};
